package designpattern.proxy;

import designpattern.proxy.Static.ReallyDoSubject;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class JdkDynamicProxy implements InvocationHandler {

    private final ReallyDoSubject reallyDoSubject;

    public JdkDynamicProxy(ReallyDoSubject reallyDoSubject) {
        this.reallyDoSubject = reallyDoSubject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object obj = null;
        try {
            obj = method.invoke(reallyDoSubject,args);
        }catch (Exception e){
            e.printStackTrace();
        }
        return obj;
    }
}
